package com.example.qxfw.dataBaseManager.nyzjk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.ny.BadCondition;
import com.example.qxfw.common.entity.ny.Goodcondition;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.common.mapper.BadConditionMapperXml;
import com.example.qxfw.common.mapper.CommonMapper;
import com.example.qxfw.common.mapper.GoodconditionMapperXml;
import com.example.qxfw.common.mapper.StationInfoMapperXml;
import com.example.qxfw.dataBaseManager.nyzjk.service.TjszService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   10:46
 * @description : 此类用来
 ***************************************/
@Service
public class TjszServiceImpl implements TjszService {

    @Autowired
    private BadConditionMapperXml badConditionMapperXml;

    @Autowired
    private CommonMapper<BadCondition> commonMapperBadCondition;

    @Autowired
    private StationInfoMapperXml stationInfoMapperXml;

    @Autowired
    private GoodconditionMapperXml goodconditionMapperXml;

    @Override
    public List<BadCondition> selectByIndexId(final Long indexId) {
        return this.badConditionMapperXml.selectList(new LambdaQueryWrapper<BadCondition>()
                .eq(BadCondition::getIndexid, indexId));
    }

    @Override
    public Integer insertBadCondition(final BadCondition badCondition) {
        return this.badConditionMapperXml.insertSelective(badCondition);
    }

    @Override
    public Integer updateBadCondition(final BadCondition badCondition) {
        return this.badConditionMapperXml.updateByPrimaryKeySelective(badCondition);
    }

    @Override
    public Integer deleteBadCondition(final BadCondition badCondition) {
        return this.badConditionMapperXml.delete(new LambdaQueryWrapper<BadCondition>()
                .eq(StringUtils.isNotBlank(badCondition.getClimatecondition()), BadCondition::getClimatecondition, badCondition.getClimatecondition())
                .eq(badCondition.getClimateconditionvalue() != Integer.parseInt(null), BadCondition::getClimateconditionvalue, badCondition.getClimateconditionvalue())
                .eq(badCondition.getTimesize() != Integer.parseInt(null), BadCondition::getTimesize, badCondition.getTimesize())
                .eq(badCondition.getTimetype() != Integer.parseInt(null), BadCondition::getTimetype, badCondition.getTimetype())
                .eq(badCondition.getContrasttype() != Integer.parseInt(null), BadCondition::getContrasttype, badCondition.getContrasttype())
                .eq(StringUtils.isNotBlank(badCondition.getBadconditions()), BadCondition::getBadconditions, badCondition.getBadconditions())
                .eq(badCondition.getIsmonitor() != Integer.parseInt(null), BadCondition::getIsmonitor, badCondition.getIsmonitor())
                .eq(StringUtils.isNotBlank(badCondition.getDatasource()), BadCondition::getDatasource, badCondition.getDatasource())
        );
    }

    @Override
    public List<StationInfo> selectStationInfo() {
        return this.stationInfoMapperXml.selectList(null);
    }

    @Override
    public List<Goodcondition> selectGoodCondition(final Long indexId) {
        return this.goodconditionMapperXml.selectList(new LambdaQueryWrapper<Goodcondition>()
                .eq(Goodcondition::getIndexid,indexId));
    }

    @Override
    public Integer saveGoodCondition(final Goodcondition goodcondition) {
        return this.goodconditionMapperXml.insertSelective(goodcondition);
    }

    @Override
    public Integer updateGoodCondition(final Goodcondition goodcondition) {
        return this.goodconditionMapperXml.updateByPrimaryKeySelective(goodcondition);
    }

    @Override
    public Integer deleteGoodCondition(final Goodcondition goodcondition) {
        return this.goodconditionMapperXml.delete(new LambdaQueryWrapper<Goodcondition>()
                .eq(StringUtils.isNotBlank(goodcondition.getIndexcondition()), Goodcondition::getIndexcondition, goodcondition.getIndexcondition())
                .eq(goodcondition.getWeatherconditionvalue() != Integer.parseInt(null), Goodcondition::getWeatherconditionvalue, goodcondition.getWeatherconditionvalue())
                .eq(goodcondition.getTimesize() != Integer.parseInt(null), Goodcondition::getTimesize, goodcondition.getTimesize())
                .eq(goodcondition.getTimetype() != Integer.parseInt(null), Goodcondition::getTimetype, goodcondition.getTimetype())
                .eq(goodcondition.getContrasttype() != Integer.parseInt(null), Goodcondition::getContrasttype, goodcondition.getContrasttype())
                .eq(StringUtils.isNotBlank(goodcondition.getGoogcondition()), Goodcondition::getGoogcondition, goodcondition.getGoogcondition())
                .eq(StringUtils.isNotBlank(goodcondition.getDatasource()), Goodcondition::getDatasource, goodcondition.getDatasource())
        );
    }

    @Override
    public Integer deleteGoodConditionByIndexId(Long indexId) {
        return this.goodconditionMapperXml.delete(new LambdaQueryWrapper<Goodcondition>()
                .eq(Goodcondition::getIndexid, indexId));
    }

    @Override
    public Integer saveBadCondition(BadCondition badCondition) {
        List<BadCondition> badConditions = this.badConditionMapperXml.selectList(new LambdaQueryWrapper<BadCondition>()
                .eq(BadCondition::getClimatecondition, badCondition.getClimatecondition())
                .eq(BadCondition::getClimateconditionvalue, badCondition.getClimateconditionvalue())
                .eq(BadCondition::getTimesize, badCondition.getTimesize())
                .eq(BadCondition::getTimetype, badCondition.getTimetype())
                .eq(BadCondition::getDatasource, badCondition.getDatasource())
                .eq(BadCondition::getContrasttype, badCondition.getContrasttype())
        );
        if (badConditions.size() > 0) {
            return 0;
        }else  {
            return this.badConditionMapperXml.insertSelective(badCondition);
        }
    }

    @Override
    public Integer deleteBadConditionByAll(BadCondition badCondition) {
        return this.badConditionMapperXml.delete(new LambdaQueryWrapper<BadCondition>()
                .eq(BadCondition::getClimatecondition, badCondition.getClimatecondition())
                .eq(BadCondition::getClimateconditionvalue, badCondition.getClimateconditionvalue())
                .eq(BadCondition::getTimesize, badCondition.getTimesize())
                .eq(BadCondition::getTimetype, badCondition.getTimetype())
                .eq(BadCondition::getDatasource, badCondition.getDatasource())
                .eq(BadCondition::getContrasttype, badCondition.getContrasttype())
        );
    }

    @Override
    public Integer deleteBadConditionByIndexId(Long indexId) {
        return this.badConditionMapperXml.delete(new LambdaQueryWrapper<BadCondition>()
                .eq(BadCondition::getIndexid, indexId));
    }
}
